package com.ts.order.controller;

import com.ts.common.security.annotation.LoginUser;
import com.ts.common.security.dto.UserToken;
import com.ts.order.dto.OrderDTO;
import com.ts.order.entity.Order;
import com.ts.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ts.common.entity.ResponseResult;

import java.util.List;

@RestController
@RequestMapping("/order")
@Slf4j
public class OrderController {

    @Autowired
    private OrderService orderService;
    @GetMapping("/action/query")
    public ResponseResult query() {
        List<Order> list = orderService.list();
        return ResponseResult.success(list);
    }

    @GetMapping("/{id}")
    public ResponseResult query(@PathVariable Integer id) {
        Order order = orderService.getById(id);
        return ResponseResult.success(order);
    }

    @PostMapping
    public ResponseResult create(@LoginUser UserToken userToken ,@RequestBody OrderDTO orderDTO) {
        orderService.create(userToken,orderDTO);
        return ResponseResult.success();
    }

}
